package test_model_base;


import java.sql.Date;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.servlet.model.base.Area;
import com.servlet.model.base.Study;

public class StudyTest extends TestCase {
	private Study study;
	private Area area;

	@Before
	public void setUp() throws Exception {
		super.setUp();
		area = new Area(91400, "france", "orsay");
		study = new Study("jialin.liu@u-psud.fr", "ifips", 
				(Date) Date.valueOf("2011-05-09"), (Date) Date.valueOf("2011-08-09"), 
				"informatique", area);
	}

	@After
	public void tearDown() throws Exception {
		study = null;
		area = null;
	}

	@Test
	public void testStudy() {
		study = new Study();
		Assert.assertNull(study.getEmail());
		Assert.assertNull(study.getSchool());
		Assert.assertNull(study.getMajor());
		Assert.assertNull(study.getArea());
		Assert.assertNull(study.getDateBegin());
		Assert.assertNull(study.getDateEnd());
		Assert.assertEquals(false, study.getIs_modified_major());
		Assert.assertEquals(false, study.getIs_modified_area());
		Assert.assertEquals(false, study.getIs_modified_date_begin());
		Assert.assertEquals(false, study.getIs_modified_date_end());
		Assert.assertEquals(false, study.getIs_modified_school());
	}

	@Test
	public void testStudyStringStringDateDateStringInt() {
		area = new Area(91119, "chine", "gif");
		study = new Study("jialin.liu@u-psud.fr", "hust", 
				(Date) Date.valueOf("2011-09-09"), (Date) Date.valueOf("2012-09-09"), 
				"optro", area);
		Assert.assertEquals("optro", study.getMajor());
		Assert.assertEquals("jialin.liu@u-psud.fr", study.getEmail());
		Assert.assertEquals("hust", study.getSchool());
		Assert.assertEquals(area, study.getArea());
		Assert.assertEquals((Date) Date.valueOf("2011-09-09"), study.getDateBegin());
		Assert.assertEquals((Date) Date.valueOf("2012-09-09"), study.getDateEnd());
		Assert.assertEquals(false, study.getIs_modified_area());
		Assert.assertEquals(false, study.getIs_modified_date_begin());
		Assert.assertEquals(false, study.getIs_modified_date_end());
		Assert.assertEquals(false, study.getIs_modified_major());
		Assert.assertEquals(false, study.getIs_modified_school());
	}

	@Test
	public void testGetEmail() {
		Assert.assertEquals("jialin.liu@u-psud.fr", study.getEmail());
	}

	@Test
	public void testGetSchool() {
		Assert.assertEquals("ifips", study.getSchool());
	}

	@Test
	public void testGetDateBegin() {
		Assert.assertEquals((Date) Date.valueOf("2011-05-09"), study.getDateBegin());
	}

	@Test
	public void testGetDateEnd() {
		Assert.assertEquals((Date) Date.valueOf("2011-08-09"), study.getDateEnd());
	}

	@Test
	public void testGetMajor() {
		Assert.assertEquals("informatique", study.getMajor());
	}

	@Test
	public void testGetIs_modified_school() {
		Assert.assertEquals(false, study.getIs_modified_school());
	}

	@Test
	public void testGetIs_modified_major() {
		Assert.assertEquals(false, study.getIs_modified_major());
	}

	@Test
	public void testGetIs_modified_date_begin() {
		Assert.assertEquals(false, study.getIs_modified_date_begin());
	}

	@Test
	public void testGetIs_modified_date_end() {
		Assert.assertEquals(false, study.getIs_modified_date_end());
	}

	@Test
	public void testSetIs_modified_school() {
		study.setIs_modified_school(true);
		Assert.assertEquals(true, study.getIs_modified_school());
	}

	@Test
	public void testSetIs_modified_area() {
		study.setIs_modified_area(true);
		Assert.assertEquals(true, study.getIs_modified_area());
	}

	@Test
	public void testSetIs_modified_major() {
		study.setIs_modified_major(true);
		Assert.assertEquals(true, study.getIs_modified_major());
	}

	@Test
	public void testSetIs_modified_date_begin() {
		study.setIs_modified_date_begin(true);
		Assert.assertEquals(true, study.getIs_modified_date_begin());
	}

	@Test
	public void testSetIs_modified_date_end() {
		study.setIs_modified_date_end(true);
		Assert.assertEquals(true, study.getIs_modified_date_end());
	}

	@Test
	public void testSetSchool() {
		study.setSchool("hust");
		Assert.assertEquals("hust", study.getSchool());
	}

	@Test
	public void testSetDateBegin() {
		Date d = Date.valueOf("2006-09-01");
		study.setDateBegin(d);
		Assert.assertEquals(d, study.getDateBegin());
	}

	@Test
	public void testSetDateEnd() {
		Date d = Date.valueOf("2009-09-01");
		study.setDateEnd(d);
		Assert.assertEquals(d, study.getDateEnd());
	}

	@Test
	public void testSetMajor() {
		study.setMajor("optro");
		Assert.assertEquals("optro", study.getMajor());
	}

	@Test
	public void testSetArea() {
		Area a = new Area(33033, "chine", "wuhan"); 
		study.setArea(a);
		Assert.assertEquals(a, study.getArea());
	}

	@Test
	public void testGenerateInsertSQL() {
		Assert.assertEquals("INSERT INTO study VALUES ('jialin.liu@u-psud.fr' ,'ifips' ,'2011-05-09' ," +
				"'2011-08-09' ,'informatique' ," + ("91400franceorsay").hashCode() + ")",
				study.generateInsertSQL());
	}

	@Test
	public void testGenerateDeleteSQL() {
		Assert.assertEquals("DELETE FROM study WHERE email='jialin.liu@u-psud.fr' AND school='ifips' AND date_begin='2011-05-09'",
				study.generateDeleteSQL());
	}

}
